package com.android.cargoapp;

import com.android.cargoapp.codescanner.IntentIntegrator;
import com.android.cargoapp.codescanner.IntentResult;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class CargoApp extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cargo_app);
        
        ((Button) findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				onClickmich(v);
			}
		});
    }
    
    public void onClickmich(View view){
    	IntentIntegrator ii = new IntentIntegrator(this);
    	ii.initiateScan();
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	IntentResult ir = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    	String str = "requestCode:" + requestCode + ".\n" + "resultCode:" + resultCode; 
    	if(ir != null && resultCode == RESULT_OK && requestCode == IntentIntegrator.REQUEST_CODE) {
    		((TextView) findViewById(R.id.textView1)).setText("Code: " + ir.getContents() + ".\n" + "Type: " + ir.getFormatName() + ".\n" + str);
    	} else {
    		((TextView) findViewById(R.id.textView1)).setText("NULL: "+str);
    	}
    	super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_cargo_app, menu);
        return true;
    }
    
}
